package
{
	import Graphics.TileSheet;
	
	import Utils.Key;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Scene;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	public class Player extends GameObject
	{
		
		public function Player(game:Level, xml:String)
		{
			super(game, xml);
		}
		
		public override function Update(deltaTime:int):void
		{
			super.Update(deltaTime);
			HandleInput();
		}
		
		private function HandleInput():void
		{	
			var tempX:int = worldPosition.x;
			var tempY:int = worldPosition.y;
			switch(Key.moveOrder[0])
			{
				case Key.UP:
					tempY -= velocity.y;
					//currentDirection = direction[0];
					break;
				case Key.DOWN:
					tempY += velocity.y;
					//currentDirection = direction[2];
					break;
				case Key.LEFT:
					tempX -= velocity.x;
					//currentDirection = direction[3];
					break;
				case Key.RIGHT:
					tempX += velocity.x;
					//currentDirection = direction[1];
					break;
				default:
					break;
			}
			Move(new Point(tempX, tempY));
		}
		
		protected override function Move(futurePosition:Point):void
		{
			super.Move(futurePosition);
			var row:int = futurePosition.x/level.TileSize;
			var column:int = futurePosition.y/level.TileSize;
			
			var tile:int = level.World[column][row];
			
			if((tile == 0 || tile > 100))
			{
				worldPosition = futurePosition;
			}
			
		}
	}
}

